package com.xuexiang.xui_lib.component.toast;

import com.xuexiang.xui_lib.ResourceTable;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.VectorElement;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

/**
 * This file is part of XToast.
 * <p>
 * XToast is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <p>
 * XToast is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with XToast.  If not, see <http://www.gnu.org/licenses/>.
 */
final class Utils {
    private Utils() {
    }

    static Element tintIcon(ShapeElement element, int tintColor) {
        RgbColor rgbColor = RgbColor.fromArgbInt(tintColor);
        element.setRgbColor(rgbColor);
        return element;
    }

    static Element tint9PatchDrawableFrame(Context context, int tintColor) {
        ShapeElement toastElement = new ShapeElement(context, ResourceTable.Graphic_xtoast_frame);
        return tintIcon(toastElement, tintColor);
    }

    static void setBackground(Component view, Element element) {
        view.setBackground(element);
    }

    static void setImageBackground(Image view, VectorElement element){
        view.setBackground(element);
    }

    static VectorElement tintImageIcon(VectorElement element, int tintColor) {
//        element.set(tintColor, PorterDuff.Mode.SRC_IN);
        return element;
    }

    static VectorElement getVectorDrawable(Context context, int id) {
        VectorElement element = new VectorElement(context,id);
        return element;
    }

    static int getColor(Context context, int color) {
        return context.getColor(color);
    }
}
